package prototype.clone;

import java.util.Date;

/**
 * @Author: 蔡翔
 * @Date: 2019/12/7 13:26
 * @Version 1.0
 */
public class Pig implements Cloneable{
    private String namme;
    private Date birthday;

    public Pig(String namme, Date birthday) {
        this.namme = namme;
        this.birthday = birthday;
    }

    public String getNamme() {
        return namme;
    }

    public void setNamme(String namme) {
        this.namme = namme;
    }

    public Date getBirthday() {
        return birthday;
    }

    public void setBirthday(Date birthday) {
        this.birthday = birthday;
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        //1.深克隆 ( 克隆指定变量 ) ，，这样克隆出来 对象的成员变量就不引用 同一个对象了。
        Pig pig = (Pig) super.clone();
        pig.birthday = (Date)pig.birthday.clone();
        return pig;

        //2.浅克隆
        //return super.clone();
    }

    @Override
    public String toString() {
        return "Pig{" +
                "namme='" + namme + '\'' +
                ", birthday=" + birthday +
                '}'+super.toString();
    }
}
